<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
          <el-form-item label="创建者" prop="createBy">
        <el-input v-model="dataForm.createBy" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="更新者" prop="updateBy">
        <el-input v-model="dataForm.updateBy" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="事件" prop="subject">
        <el-input v-model="dataForm.subject" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="发生地点" prop="occurLocation">
        <el-input v-model="dataForm.occurLocation" placeholder=""></el-input>
      </el-form-item>
<!--          <el-form-item label="" prop="lng">-->
<!--        <el-input v-model="dataForm.lng" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--          <el-form-item label="" prop="lat">-->
<!--        <el-input v-model="dataForm.lat" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--          <el-form-item label="" prop="occurGrid">-->
<!--        <el-input v-model="dataForm.occurGrid" placeholder=""></el-input>-->
<!--      </el-form-item>-->
          <el-form-item label="发生时间" prop="occurTime">
        <el-input v-model="dataForm.occurTime" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="是否重要" prop="isImportant">
        <el-input v-model="dataForm.isImportant" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="是否紧急" prop="isUrgent">
        <el-input v-model="dataForm.isUrgent" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="序列号" prop="serialNumber">
        <el-input v-model="dataForm.serialNumber" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="数据源" prop="source">
        <el-input v-model="dataForm.source" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="创建部门" prop="createDept">
        <el-input v-model="dataForm.createDept" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="事件状态" prop="issueStatus">
        <el-input v-model="dataForm.issueStatus" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="部门ID" prop="deptId">
        <el-input v-model="dataForm.deptId" placeholder=""></el-input>
      </el-form-item>
<!--          <el-form-item label="" prop="attachment">-->
<!--        <el-input v-model="dataForm.attachment" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--          <el-form-item label="" prop="hasAttachment">-->
<!--        <el-input v-model="dataForm.hasAttachment" placeholder=""></el-input>-->
<!--      </el-form-item>-->
<!--          <el-form-item label="" prop="hasDeadline">-->
<!--        <el-input v-model="dataForm.hasDeadline" placeholder=""></el-input>-->
<!--      </el-form-item>-->
          <el-form-item label="是否锁定" prop="isLocked">
        <el-input v-model="dataForm.isLocked" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="在线登记" prop="enterName">
        <el-input v-model="dataForm.enterName" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="完成时间" prop="doneTime">
        <el-input v-model="dataForm.doneTime" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="------后面的都待定------" prop="collaborationNo">
        <el-input v-model="dataForm.collaborationNo" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="collaborationSource">
        <el-input v-model="dataForm.collaborationSource" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="level">
        <el-input v-model="dataForm.level" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="delFlag">
        <el-input v-model="dataForm.delFlag" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="qualityAnalysis">
        <el-input v-model="dataForm.qualityAnalysis" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="lastProcessTime">
        <el-input v-model="dataForm.lastProcessTime" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="uringPersonId">
        <el-input v-model="dataForm.uringPersonId" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="yellowSupervise">
        <el-input v-model="dataForm.yellowSupervise" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="yellowSuperviseCount">
        <el-input v-model="dataForm.yellowSuperviseCount" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="redSupervise">
        <el-input v-model="dataForm.redSupervise" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="isTimeout">
        <el-input v-model="dataForm.isTimeout" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="categoryCode">
        <el-input v-model="dataForm.categoryCode" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="categoryName">
        <el-input v-model="dataForm.categoryName" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="createDeptName">
        <el-input v-model="dataForm.createDeptName" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="currentDeptCode">
        <el-input v-model="dataForm.currentDeptCode" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="currentDeptName">
        <el-input v-model="dataForm.currentDeptName" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="coordinateType">
        <el-input v-model="dataForm.coordinateType" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="isBeingInvalidated">
        <el-input v-model="dataForm.isBeingInvalidated" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="isInstructions">
        <el-input v-model="dataForm.isInstructions" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="issueDescription">
        <el-input v-model="dataForm.issueDescription" placeholder=""></el-input>
      </el-form-item>
          <el-form-item label="" prop="isThereRiskCivilToCriminal">
        <el-input v-model="dataForm.isThereRiskCivilToCriminal" placeholder=""></el-input>
      </el-form-item>
      </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  id: '',  createBy: '',  createTime: '',  updateBy: '',  updateTime: '',  subject: '',  occurLocation: '',  lng: '',  lat: '',  occurGrid: '',  occurTime: '',  isImportant: '',  isUrgent: '',  serialNumber: '',  source: '',  createDept: '',  issueStatus: '',  deptId: '',  attachment: '',  hasAttachment: '',  hasDeadline: '',  isLocked: '',  enterName: '',  doneTime: '',  collaborationNo: '',  collaborationSource: '',  level: '',  delFlag: '',  qualityAnalysis: '',  lastProcessTime: '',  uringPersonId: '',  yellowSupervise: '',  yellowSuperviseCount: '',  redSupervise: '',  isTimeout: '',  categoryCode: '',  categoryName: '',  createDeptName: '',  currentDeptCode: '',  currentDeptName: '',  coordinateType: '',  isBeingInvalidated: '',  isInstructions: '',  issueDescription: '',  isThereRiskCivilToCriminal: ''});

const rules = ref({
          createBy: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          createTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          updateBy: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          updateTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          subject: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          occurLocation: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          lng: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          lat: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          occurGrid: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          occurTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isImportant: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isUrgent: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          serialNumber: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          source: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          createDept: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          issueStatus: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          deptId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          attachment: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          hasAttachment: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          hasDeadline: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isLocked: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          enterName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          doneTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          collaborationNo: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          collaborationSource: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          level: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          delFlag: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          qualityAnalysis: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          lastProcessTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          uringPersonId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          yellowSupervise: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          yellowSuperviseCount: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          redSupervise: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isTimeout: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          categoryCode: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          categoryName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          createDeptName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          currentDeptCode: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          currentDeptName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          coordinateType: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isBeingInvalidated: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isInstructions: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          issueDescription: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isThereRiskCivilToCriminal: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ]
  });

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/demo/wenben/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/demo/wenben", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
</script>
